package cn.xzq.crm.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.xzq.crm.dao.UserDao;
import cn.xzq.crm.entity.User;
import cn.xzq.crm.execption.UserException;

@Service("userService")
public class UserService {
	
	@Resource(name="userDaoImpl")
	private UserDao userDao;
	
	/**
	 * 用户登录
	 * @param user
	 * @throws UserException 
	 */
	public User login(User user) throws UserException {
		 User f_user = userDao.findOneUser(user);
		 if(!user.getPassword().equals(f_user.getUsername())){
			 throw new UserException("用户名或者密码有误！");
		 }
		return f_user;
	}
	
	/**
	 * 查找所有用户
	 */
	public List<User> findAll(){
		return userDao.findAll();
	}
	
	/**
	 * 根据id查找一个用户
	 */
	public User findOneById(String uid){
		return userDao.findOneById(uid);
	}
	
}
